package org.vy.dal.dao;

import org.vy.dal.CommonSeqProvider;
import org.vy.dal.QueryManager;

public class VySubscriptionTransactionDAO {
	private static final String FIND_TRANSACTION = "SELECT * FROM <TABLE> WHERE SUBSCRIPTION_ID=m_SubscriptionId and FOR_M_Q_Y=m_ForMQY and VY_ID=m_VyId";
	private static final String FIND_BY_ID = "SELECT * FROM <TABLE> WHERE VY_SUBS_TRANS_ID=m_VySubsTransId";
	private static final String DELETE_BY_REPORT_ID = "DELETE FROM <TABLE> WHERE REPORT_INSTANCE_ID = m_ReportInstanceId";
	private static final String INSERT = "INSERT INTO <TABLE> (VY_SUBS_TRANS_ID,SUBSCRIPTION_ID,FOR_M_Q_Y,VY_ID,ADDRESS_ID,IS_DISPATCHED,DISPATCHED_BY,DISPATCH_MODE,DISPATCH_DATE,COMMENTS,REPORT_INSTANCE_ID,CREATED_DATE) VALUES (m_VySubsTransId,m_SubscriptionId,m_ForMQY,m_VyId,m_AddressId,m_IsDispatched,m_DispatchedBy,m_DispatchMode,m_DispatchDate,m_Comments,m_ReportInstanceId,m_CreatedDate);";

	public static VySubscriptionTransactionDO findTransaction(String subId,
			String vyId, int forMQY) throws Exception {
		VySubscriptionTransactionDO dto = new VySubscriptionTransactionDO();
		dto.setSubscriptionId(subId);
		dto.setVyId(vyId);
		dto.setForMQY(forMQY);
		dto = (VySubscriptionTransactionDO) QueryManager.executeQuery(dto,
				FIND_TRANSACTION);
		return dto;
	}

	public static VySubscriptionTransactionDO findById(int transId)
			throws Exception {
		VySubscriptionTransactionDO dto = new VySubscriptionTransactionDO();
		dto.setVySubsTransId(transId);
		dto = (VySubscriptionTransactionDO) QueryManager.executeQuery(dto,
				FIND_BY_ID);
		return dto;
	}

	public static VySubscriptionTransactionDO insert(
			VySubscriptionTransactionDO dto) throws Exception {
		dto.setVySubsTransId(0);
		dto = (VySubscriptionTransactionDO) QueryManager.executeInsert(dto,
				INSERT);
		return dto;
	}

	public static boolean delete(int reportInstanceId) throws Exception {
		VySubscriptionTransactionDO dto = new VySubscriptionTransactionDO();
		dto.setReportInstanceId(reportInstanceId);
		boolean i = QueryManager.executeDelete(dto, DELETE_BY_REPORT_ID);
		return i;
	}
}
